/**
 *	VisualGroup JavaScript prototype Classes, version 0.1
 *  (c) 2008 Bill Vison <vison_ruan@126.com>
 *  unuse action defined
 *
/*--------------------------------------------------------------------------*/
Vsg.CrossDomainAction  = function(form, options){
    Vsg.CrossDomainAction.superclass.constructor.call(this, form, options);
};

Ext.extend(Vsg.CrossDomainAction, Ext.form.Action, {
    
    type : 'crossdomain',
	
	_response:null,

    run : function(){
        var $o = this.options;
        var $method = this.getMethod();

		this.handleResponse(this._response);

    },
	
	setResponse:function(response) {
		this._response = response;
	},

    success : function($responseObj){

		this.result = $responseObj.result;
		if (this.options.success == null) {
			throw new Vsg.CrossDomainAction.Exception("Do not set ['success'] handler method ,please reset it !" ,null , Vsg.CrossDomainAction.Exception.HandlerNotFount);
		}
		
		// --- call back ---
		this.afterAction(this , true);
    },

	beforeAction : function(action){
        var o = action.options;
        if(o.waitMsg){
			var $thisform = action.form;

            if($thisform.waitMsgTarget === true){
                $thisform.el.mask(o.waitMsg, 'x-mask-loading');
            }else if($thisform.waitMsgTarget){
                $thisform.waitMsgTarget = Ext.get($thisform.waitMsgTarget);
                $thisform.waitMsgTarget.mask(o.waitMsg, 'x-mask-loading');
            }else{
                Ext.MessageBox.wait(o.waitMsg, o.waitTitle || $thisform.waitTitle || 'Please Wait...');
            }

        }
    },
	
    afterAction : function(action, success){
		var $thisform = action.form;
        $thisform.activeAction = null;
        var o = action.options;
        if(o.waitMsg){
            if($thisform.waitMsgTarget === true){
                $thisform.el.unmask();
            }else if($thisform.waitMsgTarget){
                $thisform.waitMsgTarget.unmask();
            }else{
                Ext.MessageBox.updateProgress(1);
                Ext.MessageBox.hide();
            }
        }
        if(success){
            if(o.reset){
                $thisform.reset();
            }
            Ext.callback(o.success, o.scope, [$thisform, action]);
            $thisform.fireEvent('actioncomplete', $thisform, action);
        }else{
            Ext.callback(o.failure, o.scope, [$thisform, action]);
            $thisform.fireEvent('actionfailed', $thisform, action);
        }
    },		
	

    handleResponse : function(response){

		var $obj =  Ext.decode(response);

		if ($obj.success) {
			this.success($obj);
		}


    }
	
});

Vsg.CrossDomainAction.Exception = Ext.extend(Exception.CommonException,{
	name:"Vsg.CrossDomainAction.Exception",
	constructor:function($message , $name ,$value) {
		Vsg.CrossDomainAction.Exception.superclass.constructor.apply(this, arguments);
	}
});
Vsg.CrossDomainAction.Exception.HandlerNotFount = 1;